# -*- coding: utf-8 -*-
# @Time    : 2020/2/25 下午11:58
# @Author  : lilong
# @File    : basic_overload.py


"""
该例子讲的是：基础重载方法
"""


class Person():
    """人"""

    visited = 0     # 全局变量

    def __init__(self, name, age, height):
        self.__name = name      # 私有变量
        self._age = age         # 保护变量
        self.height = height

    def getName(self):
        return self.__name

    def getAge(self):
        return self._age

    def showInfo(self):
        print("name:", self.__name)
        print("age:", self._age)
        print("height:", self.height)
        print("visited:", self.visited)

        # 全局变量进行累加
        Person.visited = Person.visited + 1

    def __str__(self):
        return "name:{} \n age:{} \n height:{} \n".format(self.__name, self._age, self.height)

    # def __del__(self):
    #     # 会在程序结束时自动运行运行
    #     print("\n 析构函数..")

    __repr__ = __str__


class Teacher(Person):
    """老师"""

    def __init__(self, name, age, height):
        # 调用基类的构造函数进行构造
        super().__init__(name, age, height)
        self.__title = None

    def getTitle(self):
        return self.__title

    def setTitle(self, title):
        self.__title = title

    def showInfo(self):
        print("title:", self.__title)
        super().showInfo()

    def __str__(self):
        return "title:{}".format(self.__title)


def testPerson():
    """测试方法"""

    tony = Person("Tony", 25, 1.77)
    tony.showInfo()
    print()
    print(tony)

    jenny = Teacher("Jenny", 34, 1.68)
    jenny.setTitle("教授")
    print(jenny)
    jenny.showInfo()


testPerson()
